import { loader } from "@monaco-editor/react";
import * as monaco from "monaco-editor";

// 配置 MonacoEnvironment 以完全禁用 workers，避免 CSP 限制
self.MonacoEnvironment = {
  getWorker: function () {
    // 返回一个模拟的 worker 对象，避免 postMessage 错误
    return new Promise((resolve) => {
      const mockWorker = {
        postMessage: () => {},
        onmessage: null,
        onerror: null,
        terminate: () => {}
      };
      resolve(mockWorker as any);
    });
  }
};

// 配置 Monaco Editor 使用本地包
loader.config({ monaco });

export { monaco };